<?php 
require_once 'sesi_login.php';
require_once 'konfigurasi.php';

fungsi('pengguna');

define('PAGE', 'Admin Jadwal Praktikum');
define('PAGE_ICO', 'icon-stats');
define('PAGE_URL', 'admin_jadwal_praktikum.php');

panggil_header();
koneksi_buka();

$kelas = "";
$materi = "";

if(isset($_POST['kelas'])){
	$kelas = $_POST['kelas'];
	if($kelas == '0'){
		$kelas = "";
	}
}

if(isset($_POST['materi'])){
	$materi = $_POST['materi'];
	if($materi == '0'){
		$materi = "";
	}
}

if(isset($_GET['kelas'])){
	$kelas = $_GET['kelas'];
	if($kelas == '0'){
		$kelas = "";
	}
}

if(isset($_GET['materi'])){
	$materi = $_GET['materi'];
	if($materi == '0'){
		$materi = "";
	}
}

$array['1'] =  'senin'; 
		 $array['2'] =  'selasa'; 
		 $array['3'] =  'rabu'; 
		 $array['4'] =  'kamis'; 
		 $array['5'] =  'jumat'; 
		 $array['6'] =  'sabtu'; 
		 $array['7'] =  'minggu'; 

$text_q_jadwal = "select IFNULL(c.hari, '-') as j_hari, 
				IFNULL(c.id, '-') as j_id, 
				IFNULL(c.jam_mulai, '-') as j_mulai, 
				IFNULL(c.jam_selesai, '-') as j_selesai,
				a.nis as nis,  
				a.nama as s_nama, d.nama as m_nama, b.nama as k_nama,
				a.id as s_id, d.id as m_id 
				from siswa a
				left join kelas b on a.kelas = b.id
				left join jadwal_praktikum c on a.id = c.siswa
				left join materi d on d.tipe_kelas = b.tipe 
				where d.id like'%$materi%' and b.id like'%$kelas%'";
//echo $text_q_jadwal;

$q_jadwal = mysql_query($text_q_jadwal);

?>

<div class="content">
                
	<div class="page-header">
		<div class="icon">
			<span class="ico-arrow-right"></span>
		</div> 
		<h1> Jadwal Praktikum<small>SDN I</small></h1>
	</div>
	
	<div class="row-fluid">
		<div class="span12">                

			<div class="block">
				<div class="head">                                
					<h2>Input Jadwal</h2>
					<ul class="buttons">             
						<li><a href="#" onClick="source('form_pa'); return false;"><div class="icon"><span class="ico-info"></span></div></a></li>
					</ul>                                                                  
				</div>        
				<form id="validate" method="post" action="admin_jadwal_praktikum.php">
                	<div class="data-fluid">
						<div class="row-form">
							<div class="span2">Kelas</div>
							<div class="span5">
								<select name="kelas" class="select" style="width: 100%;">
									<?php 
										
										if($kelas!=""){
											$text_q_kelas1 = "select * from kelas where id=$kelas";
										
											$q_kelas1= mysql_query($text_q_kelas1);
											if($dt_kelas = mysql_fetch_array($q_kelas1)){
												$kelas_nama = $dt_kelas['nama'];
									?>
											
										<option value="<?php echo $kelas;?>"><?php echo $kelas_nama?></option>
									
									<?php }}?>
									
										<option value="0">-- semua --</option>
									
									<?php 
									
										$text_q_kelas = "select * from kelas";
										$q_kelas = mysql_query($text_q_kelas);
										while($dt_kelas = mysql_fetch_array($q_kelas)){?>
											<option value="<?php echo $dt_kelas['id'];?>"><?php echo $dt_kelas['nama'];?></option>
									<?php }?>                                        
								</select>
							</div>
						</div>       
						<div class="row-form">
							<div class="span2">Materi</div>
							<div class="span6">
								<select name="materi" class="select" style="width: 100%;">
									<?php 
										
										if($materi!=""){
											$text_q_materi1 = "select * from materi where id=$materi";
										
											$q_materi1= mysql_query($text_q_materi1);
											if($dt_materi = mysql_fetch_array($q_materi1)){
												$materi_nama = $dt_materi['nama'];
									?>
											
										<option value="<?php echo $materi;?>"><?php echo $materi_nama?></option>
									
									<?php }}?>
									
										<option value="0">-- semua --</option>
									
									<?php 
									
										$text_q_materi = "select * from materi";
										$q_materi = mysql_query($text_q_materi);
										while($dt_materi = mysql_fetch_array($q_materi)){?>
											<option value="<?php echo $dt_materi['id'];?>"><?php echo $dt_materi['nama'];?></option>
									<?php }?>                                        
								</select>
							</div>
						</div>                  
						
						<div class="row-form">
							<div class="span2"></div>
							<div class="span9">                       
								<input type="submit" class="btn btn-primary" value="Edit"/> 		
								<input type="reset" class="btn btn-warning" value="Batal"/>       
							</div>   
						</div>
					</div>
				</form>        
			</div>
		</div>  
	</div>
	<?php
		if($kelas!="" && $materi!=""){
			
	?>
		<div class="row-fluid">
			<div class="span12">                

				<div class="block">
					<div class="head">                                
						<h2>Atur Jadwal Satu Kelas</h2>
						<ul class="buttons">             
							<li><a href="#" onClick="source('form_pa'); return false;"><div class="icon"><span class="ico-info"></span></div></a></li>
						</ul>                                                                  
					</div>        
					<form id="validate" method="post" action="modul/admin_jadwal_praktikum/kelas_update.php">
						<div class="data-fluid">
							<div class="row-form">
								<div class="span2">Hari</div>
								<div class="span4">
									<select name="hari" class="select" style="width: 100%;">
										<option value="1">senin</option>       
										<option value="2">selasa</option>
										<option value="3">rabu</option>
										<option value="4">kamis</option>
										<option value="5">jumat</option>
										<option value="6">sabtu</option>
										<option value="7">minggu</option>                                 
									</select>
								</div>
							</div>       
							<div class="row-form">
								<div class="span2">Mulai</div>
								<div class="span5">
									<div class="input-append timepicker3">
										<input data-format="hh:mm:ss" name="mulai" type="text"></input>
										<span class="add-on">
										  <i data-time-icon="icon-time" data-date-icon="icon-calendar">
										  </i>
										</span>
									</div>
								</div>							
							</div>                  
							
							<div class="row-form">
								<div class="span2">Selesai</div>
								<div class="span5">
									<div class="input-append timepicker3">
										<input data-format="hh:mm:ss" name="selesai" type="text"></input>
										<span class="add-on">
										  <i data-time-icon="icon-time" data-date-icon="icon-calendar">
										  </i>
										</span>
									</div>
								</div>   
							</div>
							<div class="row-form">
								<div class="span2"></div>
								<div class="span9">                       
									<input type="hidden" name="kelas" value="<?php echo $kelas;?>"/> 		
									<input type="hidden" name="materi" value="<?php echo $materi;?>"/>
									<input type="submit" class="btn btn-primary" value="Simpan"/> 		
									<input type="reset" class="btn btn-warning" value="Batal"/>       
								</div>   
							</div>
						</div>
					</form>        
				</div>
			</div>  
		</div>
	
	
	<?php
		}	
	?>
	
	<div class="row-fluid">
		<div class="span12">
			<div class="block">
				<div class="head purple">
					<div class="icon"><span class="ico-book-3"></span></div>
					<h2>Daftar Jadwal</h2>
					<ul class="buttons">
						<li><a href="#" onClick="source('table_hover'); return false;"><div class="icon"><span class="ico-info"></span></div></a></li>
					</ul> 
					<ul class="buttons">
						<li><a id="tambah-latihan" href="#"><div class="icon"><span class="ico-plus-sign"></span></div></a></li>
					</ul>                      
					                                                         
				</div>    
				           
				<div class="data-fluid">
					<table id="table-editable" cellpadding="0" cellspacing="0" width="100%" class="table fpTable lcnp">
						<thead>
							<tr>
								<th width="10%">
									No
								</th>
								<th width="10%">
									NIS
								</th>
							
								<th width="20%">
									Nama Siswa
								</th>
								<th width="10%">
									Kelas
								</th>
								<th width="20%">
									Materi
								</th>
								<th width="10%">
									Hari
								</th>
								<th width="10%">
									Mulai
								</th>
								<th width="10%">
									Selesai
								</th>
							</tr>
						</thead>
						<tbody>
							<?php
								$row = 1;
								while($dt_jadwal = mysql_fetch_array($q_jadwal)){
							?>
								<tr data-siswa="<?php echo $dt_jadwal['s_id'];?>" data-materi="<?php echo $dt_jadwal['m_id'];?>" id="<?php echo $dt_jadwal['j_id'];?>">
									<td>
										<?php echo $row; $row++;?>
									</td>
									<td>
										<?php echo $dt_jadwal['nis'];?>
									</td>
									<td>
										<?php echo $dt_jadwal['s_nama'];?>
									</td>
									<td>
										<?php echo $dt_jadwal['k_nama'];?>
									</td>
									<td>
										<?php echo $dt_jadwal['m_nama'];?>
									</td>
									<td class="editable-column">
										<?php echo $dt_jadwal['j_hari']!='-'?$array[$dt_jadwal['j_hari']]:'-';?>
									</td>
									<td class="editable-time-column">
										<?php echo $dt_jadwal['j_mulai'];?>
									</td>
									<td class="last-child-text editable-time-column">
										<?php echo $dt_jadwal['j_selesai'];?>
									</td>
								</tr>
							<?php } ?>

						</tbody>
					</table>
				</div>  
				<br />
				<!--
				<div class="data-fluid">
					<div align="right">                  
						<button class="btn btn-primary" type="button">Cetak Semua</button>
					</div>   
				</div> 
				-->			 
			</div>
		</div>
	</div>
</div>

<div id="dialog-tambah-latihan" style="display:none;">
	<?php
		require_once 'modul/admin_latihan/tambah_latihan.php';
	?>
</div>

<div class="dialog" id="source" style="display: none;" title="Source"></div>

<?php
panggil_footer();
?>
